<template>
    <div>
        <city-header></city-header>
        <city-search></city-search>
        <city-list
                :hotCities="hotCities"
                :cities="cities"
                :alpha="alpha"></city-list>
        <city-alphabet
                :alpha="cities"
                @change="changeAlpha"
        ></city-alphabet>
    </div>
</template>

<script>
import axios from 'axios'
import cityHeader from './components/header'
import citySearch from './components/search.vue'
import cityList from './components/list'
import cityAlphabet from './components/alphabet.vue'

export default {
  name: 'city',
  components: {
    cityHeader,
    citySearch,
    cityList,
    cityAlphabet
  },
  data () {
    return {
      cities: {},
      hotCities: [],
      alpha: 'A'
    }
  },
  methods: {
    getCityInfo () {
      axios.get('/api/city.json').then(
        this.getCityInfoSucc
      )
    },
    getCityInfoSucc (res) {
      console.log(res)
      let data = res.data
      if (data.ret && data.data) {
        this.cities = data.data.cities
        this.hotCities = data.data.hotCities
      }
    },
    changeAlpha (letter) {
      this.alpha = letter
      // console.log(letter);
    }
  },
  mounted () {
    this.getCityInfo()
  }
}
</script>

<style lang="stylus" scoped>

</style>
